package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author ：贝
 * @date ：Created in 2022年06月08日
 * @description ：
 * 会员添加 更新
 * @version: 1.0
 */
@Service
public class MemberServiceimpl implements MemberService {
    @Autowired
    private MemberDao memberDao;


    @Override
    public Member updateBytelephone(Member member) {
        //获取手机号
        String phoneNumber = member.getPhoneNumber();
        //根据手机号去数据库查看是否有数据
        Member member1 = memberDao.selectBytelephone(phoneNumber);

        if (member1!=null){
            //存在,更新(个人认为没必要)
            member.setId(member1.getId());
            memberDao.updateByMember(member);

        }else {
            //不存在 储存
            member.setRegTime(new Date());
            memberDao.insert(member);
        }
          return memberDao.selectById(member.getId());

    }
}
